import javax.swing.*;
import java.awt.*;
import java.text.*;
import java.awt.event.*;
import java.io.*;

// class to display Frame showing digram distributions
// called by "Diagram Distribution" button on monoCard

class VigICFrame extends JFrame {
	
	private JTextArea textArea;

	public VigICFrame(int n,String s){
	   super("I.C.'s for Subalphabets");
	   
	   Container container = getContentPane();
	   container.setLayout(new FlowLayout());
	   NumberFormat form = NumberFormat.getInstance(); //format for ic
       form.setMaximumFractionDigits(5);
      
	   
 	   int[][] count = new int[n][26];
 	   int[] total = new int[n];
 	   
 	   for(int i=0;i<n;i++) total[i]=0;
 	   for(int i=0;i<n;i++)
 	     for(int j=0;j<26;j++)
 	       count[i][j]=0;
 	       
 	   for(int i=0;i<s.length();i++){
 	     int j = i%n;
 	     int c=s.charAt(i)-'a';
         count[j][c]++;
         total[j]++;
       }
  
       double[] ic = new double[n];
       for(int i=0;i<n;i++) ic[i]=0;
       
       for(int i=0;i<n;i++)
         for(int j=0;j<26;j++)
           ic[i] += count[i][j]*(count[i][j]-1);
           
       for(int i=0;i<n;i++)
         ic[i] = ic[i]/(total[i]*(total[i]-1));
       
       String sout = new String("");
       for(int i=0;i<n;i++)
          sout += (i+1) + ": " + form.format(ic[i])+ "\n";

	   textArea = new JTextArea(sout, 20, 15);
       textArea.setFont(new Font("monospaced",Font.PLAIN,12));
 	   container.add(new JScrollPane(textArea));
      
	   setSize(150,400);
	   setResizable(false);
	   setVisible(true);
	}
}
